package Student_Course;

import Grade.*;
import Main.UserLogin;

import java.util.Scanner;

public class StudentView {

    // 显示操作菜单
    public static void displayMenu() {
        System.out.println("\n=========================================");
        System.out.println("            学生界面");
        System.out.println("=========================================");
        System.out.println("请选择操作：");
        System.out.println("1. 选课");
        System.out.println("2. 查询选课信息");
        System.out.println("3. 查询成绩");
        System.out.println("4. 退选课程");
        System.out.println("5. 退出到主界面");
        System.out.println("=========================================");
    }

    // 控制学生界面的操作流程
    public static void student() throws Exception {
        Scanner scanner = new Scanner(System.in);
        boolean running = true;  // 控制学生界面是否运行

        while (running) {
            // 显示学生操作菜单
            displayMenu();

            // 获取用户输入
            System.out.print("请输入您的选择: ");

            // 检查是否有有效的整数输入
            int choice = -1;
            if (scanner.hasNextInt()) {
                choice = scanner.nextInt();
                scanner.nextLine(); // 清空输入缓冲区中的换行符
            } else {
                // 如果没有输入有效的整数，给出提示并继续下一轮输入
                System.out.println("无效输入，请输入数字选项！");
                scanner.nextLine();  // 清空输入缓冲区中的无效字符
                continue;
            }

            try {
                switch (choice) {
                    case 1:
                        CourseSelection.add();
                        break;
                    case 2:
                        CourseSelectionResult.myCourse();
                        break;
                    case 3:
                        String id = UserLogin.getUserId();
                        GradeDAO grade = new Grade();
                        grade.getMyGrade(id);
                        break;
                    case 4:
                        CourseSelectionResult.myCourse();
                        System.out.println("请输入你要退选的课程编号：");
                        int a = scanner.nextInt();
                        CourseDelete delete = new CourseDelete();
                        delete.deleteCourse(a);
                        break;
                    case 5:
                        System.out.println("\n=========================================");
                        System.out.println("正在返回主界面...");
                        System.out.println("=========================================");
                        running = false;
                        break;
                    default:
                        System.out.println("\n输入无效，请重新选择！");
                        break;
                }
            } catch (Exception e) {
                System.out.println("操作过程中出现错误: " + e.getMessage());
                e.printStackTrace();
            }

        }


    }
}
